<!DOCTYPE html>
<html lang="en">
<head>
        <title>Compilation of Linux kernel for Raspberry Pi</title>
        <meta charset="utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <link rel="shortcut icon" href="./theme/images/favicon.ico"/>
        <link rel="stylesheet" href="./theme/css/main.css" type="text/css" />
        <link href="www.j-marjanovic.io/feeds/all.atom.xml" type="application/atom+xml" rel="alternate" title="j-marjanovic.io Atom Feed" />

        <!--[if IE]>
                <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->

        <!--[if lte IE 7]>
                <link rel="stylesheet" type="text/css" media="all" href="./css/ie.css"/>
                <script src="./js/IE8.js" type="text/javascript"></script><![endif]-->

        <!--[if lt IE 7]>
                <link rel="stylesheet" type="text/css" media="all" href="./css/ie6.css"/><![endif]-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="theme/jquery.cookiesdirective.js"></script>

</head>

<body id="index" class="home">
<script type="text/javascript">
	// Using $(document).ready never hurts
	$(document).ready(function(){

		// Cookie setting script wrapper
		var cookieScripts = function () {
			// Internal javascript called
			console.log("Running");
		
			// Loading external javascript file
			$.cookiesDirective.loadScript({
				uri:'external.js',
				appendTo: 'eantics'
			});
		}
	
		/* Call cookiesDirective, overriding any default params
		
			*** These are the defaults ***
				explicitConsent: true,
				position: 'top',
				duration: 10,
				limit: 0,
				message: null,				
				cookieScripts: null,
				privacyPolicyUri: 'privacy.html',
				scriptWrapper: function(){},	
				fontFamily: 'helvetica',
				fontColor: '#FFFFFF',
				fontSize: '13px',
				backgroundColor: '#000000',
				backgroundOpacity: '80',
				linkColor: '#CA0000'
				
		*/
		
		$.cookiesDirective({
			privacyPolicyUri: 'myprivacypolicy.html',
			explicitConsent: false,
			position : 'bottom',
			scriptWrapper: cookieScripts, 
			cookieScripts: 'Google Analytics', 
			backgroundColor: '#52B54A',
			linkColor: '#ffffff'
		});
	});
</script>

	
  <!-- <header id="banner" class="body"> -->
  <!--               <h1><a href="./"><img src="http://www.launchyard.com/images/logo.png" /></a></h1> -->
  <!--       </header> --> 

  <div class="LaunchyardDetail" style="align:right;">
    <!-- <p> -->
    <!-- <img src="./theme/images/blue-pin.png" width="100" height="100" alt="Graph icon"> -->
    <!-- </p> -->
    <p><a id="sitesubtitle" href="./">j-marjanovic.io</a></p>

	<br>
    <p style="float: right; margin-right: 50px;"><a id="aboutlink" href="./pages/about.html">About</a></p>

    <br>
	<p style="float: right; margin-right: 50px;"><img src="./theme/images/icons/rss.png"> <a id="aboutlink" href="./feeds/jan-marjanovic.atom.xml">Atom feed</a></p>
    <br>

  </div>

<section id="content" >
    <div class="body">
      <article>
        <header>
          <h1 class="entry-title">
            <a href="./compilation-of-linux-kernel-for-raspberry-pi.html" rel="bookmark"
               title="Permalink to Compilation of Linux kernel for Raspberry Pi">Compilation of Linux kernel for Raspberry Pi</a></h1>

        </header>

        <div class="entry-content">
<div class="post-info">
	<ul>
        <li class="vcard author">
                 by&nbsp;<a class="url fn" href="./author/jan-marjanovic.html">Jan Marjanovic</a>
        </li>
        <li class="published" title="2015-03-01T19:00:00+01:00">
          on&nbsp;Sun 01 March 2015
        </li>

	</ul>
<p>Category: <a href="./tag/linux.html">Linux</a>, <a href="./tag/raspberry-pi.html">Raspberry Pi</a>, </p>
</div><!-- /.post-info -->          <p>Yesterday I got my Raspberry Pi 2, the evolution of the legendary Raspberry Pi. 
The evolution is the right word to describe what has changed compared to 
the previous version. The processor it is now a quad-core, it runs faster,
it has got a newer instruction set (ARMv7) and the board now incorporates 1GB
of RAM and 4 USB connector. The RCA jack is no longer present, the additional
place is being occupied by a larger extension header instead. A welcomed update
of already great hardware, in my opinion (for people complaining that it
can't play 4K video, run desktop version of the Windows, ..., well, consider
buying proper computer, RPi was meant to be cheep enough to tinker with
without fear of breaking something).</p>
<p>I am the kind of the person which thinks that compiling Linux kernel would be 
great a way to spend the Sunday. Since one of my projects with RPi includes
custom driver for communication with FPGA, I needed Linux headers and <em>kbuild</em>
system for building kernel modules (those who are not familiar with the procedure,
imagine that you are building a program linked with libraries; in this case a 
program is a kernel module and kernel and its modules represent the libraries).</p>
<p>On the Ubuntu (and I think on other Debian systems but I am not 100% sure) you
can get kernel headers and source directly from the Debian repository, something
like:</p>
<div class="highlight"><pre><span></span><code>apt-get install linux-headers-<span class="k">$(</span>uname -r<span class="k">)</span>
</code></pre></div>


<p>The above command will install the headers the headers for the currently running 
kernel. It copies the header files to /usr/src and creates link in /lib/modules/,
this gives the user tools needed to compile kernel modules.</p>
<h2>The hard way</h2>
<p>Before you continue reading I would just like to inform you that the procedure 
described in this section did not yield desired result. Although I managed to 
get a kernel image, the <em>kbuild</em> system did not work. In Thomas Alva Edison style
 I want to present a method which does not work, but at least we know it does not work. The working (and easier) procedure is described in the next section.</p>
<p>Initially I wanted to get the headers in the same way as I would on Ubuntu, by
using apt (Advanced Packaging Tool). Searching for available packages did not
show the package needed (the Raspbian was running the 3.18.7-v7+ kernel).</p>
<div class="highlight"><pre><span></span><code><span class="gp">pi@raspberrypi ~ $</span> sudo aptitude search linux-headers
<span class="go">v   linux-headers                                   -                                                           </span>
<span class="go">p   linux-headers-3.10-3-all                        - All header files for Linux 3.10 (meta-package)            </span>
<span class="go">p   linux-headers-3.10-3-all-armhf                  - All header files for Linux 3.10 (meta-package)            </span>
<span class="go">p   linux-headers-3.10-3-common                     - Common header files for Linux 3.10-3                      </span>
<span class="go">p   linux-headers-3.10-3-rpi                        - Header files for Linux 3.10-3-rpi                         </span>
<span class="go">p   linux-headers-3.12-1-all                        - All header files for Linux 3.12 (meta-package)            </span>
<span class="go">p   linux-headers-3.12-1-all-armhf                  - All header files for Linux 3.12 (meta-package)            </span>
<span class="go">p   linux-headers-3.12-1-common                     - Common header files for Linux 3.12-1                      </span>
<span class="go">p   linux-headers-3.12-1-rpi                        - Header files for Linux 3.12-1-rpi                         </span>
<span class="go">p   linux-headers-3.18.0-trunk-all                  - All header files for Linux 3.18 (meta-package)            </span>
<span class="go">p   linux-headers-3.18.0-trunk-all-armhf            - All header files for Linux 3.18 (meta-package)            </span>
<span class="go">p   linux-headers-3.18.0-trunk-common               - Common header files for Linux 3.18.0-trunk                </span>
<span class="go">p   linux-headers-3.18.0-trunk-rpi                  - Header files for Linux 3.18.0-trunk-rpi                   </span>
<span class="go">p   linux-headers-3.18.0-trunk-rpi2                 - Header files for Linux 3.18.0-trunk-rpi2                  </span>
<span class="go">p   linux-headers-3.2.0-4-all                       - All header files for Linux 3.2 (meta-package)             </span>
<span class="go">p   linux-headers-3.2.0-4-all-armhf                 - All header files for Linux 3.2 (meta-package)             </span>
<span class="go">p   linux-headers-3.2.0-4-common                    - Common header files for Linux 3.2.0-4                     </span>
<span class="go">p   linux-headers-3.2.0-4-rpi                       - Header files for Linux 3.2.0-4-rpi                        </span>
<span class="go">p   linux-headers-3.6-trunk-all                     - All header files for Linux 3.6 (meta-package)             </span>
<span class="go">p   linux-headers-3.6-trunk-all-armhf               - All header files for Linux 3.6 (meta-package)             </span>
<span class="go">p   linux-headers-3.6-trunk-common                  - Common header files for Linux 3.6-trunk                   </span>
<span class="go">p   linux-headers-3.6-trunk-rpi                     - Header files for Linux 3.6-trunk-rpi                      </span>
<span class="go">p   linux-headers-rpi                               - Header files for Linux rpi configuration (meta-package)   </span>
<span class="go">p   linux-headers-rpi-rpfv                          - This metapackage will pull in the headers for the raspbian</span>
<span class="go">p   linux-headers-rpi2-rpfv                         - This metapackage will pull in the headers for the raspbian</span>
</code></pre></div>


<p>I tried my luck with <em>linux-headers-rpi2-rpfv</em> which installed headers for
kernel 3.18.0. That might sound close enough, but Linux refuses modules which
have not been compiled with exactly the same same kernel. </p>
<p>So I decided to recompile the kernel on my laptop running Ubuntu. The procedure
of compiling on one type of machine (in this case Intel x86_64 processor) for
another (in this case ARM processor) is called cross-compilation.</p>
<p>The process of cross-compilation is described here: <a href="http://elinux.org/Raspberry_Pi_Kernel_Compilation">Raspberry Pi Kernel Compilation</a></p>
<p>Everything went fine, I got the kernel image and /lib/modules directory. The only
thing that the guide does not mention is that <em>make modules_install</em> creates 
symbolic links to the original directory. I copied the entire kernel directory
to /usr/src and recreated symbolic links, so everything should be fine.</p>
<p>At this point if everything went OK we would have a working kernel and its 
<em>kbuild</em> system which gives us the tools to compile the kernel modules out of the
tree (in a separate directory). The RPi boots up, which is a good sign, meaning
that there is nothing wrong with the kernel image. </p>
<p>However, when I try to compile the kernel module, I get the error saying that 
there is a syntax error in script in kernel module 
(the same problem as described <a href="http://stackoverflow.com/questions/17282461/scripts-recordmcount-syntax-error-when-i-try-to-build-a-linux-kernel-module-o">here</a>. The answer by Joe C states:</p>
<blockquote>
<p>Anyway, if you cross compile you don't get a /usr/src/linux-header-x.x.x/scripts dir that's usable on your target system.</p>
</blockquote>
<p>Since I previously downloaded another kernel headers from Debian repository,
I tired copying the scripts directory from there:</p>
<p>pi@raspberrypi /usr/src/linux-headers-3.18.0-trunk-rpi2 $ sudo cp -rv scripts/ ../linux-sources-3.18.8-v7+/</p>
<p>This fixed the compilation problem just to cause complete disaster when I
tried inserting the module. The following kernel message (<em>dmesg</em> command)
shows nothing promising:</p>
<div class="highlight"><pre><span></span><code><span class="o">[</span><span class="n"> 4246.164155</span><span class="o">]</span><span class="w"> </span><span class="n">Unable</span><span class="w"> </span><span class="k">to</span><span class="w"> </span><span class="n">handle</span><span class="w"> </span><span class="n">kernel</span><span class="w"> </span><span class="n">paging</span><span class="w"> </span><span class="n">request</span><span class="w"> </span><span class="k">at</span><span class="w"> </span><span class="n">virtual</span><span class="w"> </span><span class="n">address</span><span class="w"> </span><span class="n">fe220b30</span><span class="w"></span>
<span class="o">[</span><span class="n"> 4246.176292</span><span class="o">]</span><span class="w"> </span><span class="n">pgd</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">b5dd8000</span><span class="w"></span>
<span class="o">[</span><span class="n"> 4246.183812</span><span class="o">]</span><span class="w"> </span><span class="o">[</span><span class="n">fe220b30</span><span class="o">]</span><span class="w"> </span><span class="o">*</span><span class="n">pgd</span><span class="o">=</span><span class="mi">00000000</span><span class="w"></span>
<span class="o">[</span><span class="n"> 4246.192196</span><span class="o">]</span><span class="w"> </span><span class="n">Internal</span><span class="w"> </span><span class="nl">error</span><span class="p">:</span><span class="w"> </span><span class="nl">Oops</span><span class="p">:</span><span class="w"> </span><span class="mi">5</span><span class="w"> </span><span class="o">[</span><span class="n">#1</span><span class="o">]</span><span class="w"> </span><span class="n">PREEMPT</span><span class="w"> </span><span class="n">SMP</span><span class="w"> </span><span class="n">ARM</span><span class="w"></span>
<span class="o">[</span><span class="n"> 4246.202324</span><span class="o">]</span><span class="w"> </span><span class="n">Modules</span><span class="w"> </span><span class="n">linked</span><span class="w"> </span><span class="ow">in</span><span class="err">:</span><span class="w"> </span><span class="n">pi64_dev</span><span class="p">(</span><span class="n">O</span><span class="o">+</span><span class="p">)</span><span class="w"> </span><span class="n">snd_bcm2835</span><span class="w"> </span><span class="n">snd_soc_pcm512x_i2c</span><span class="w"> </span><span class="n">snd_soc_wm8804</span><span class="w"> </span><span class="n">snd_soc_pcm512x</span><span class="w"> </span><span class="n">snd_soc_tas5713</span><span class="w"> </span><span class="n">regmap_spi</span><span class="w"> </span><span class="n">regmap_i2c</span><span class="w"> </span><span class="n">snd_soc_bcm2708_i2s</span><span class="w"> </span><span class="n">regmap_mmio</span><span class="w"> </span><span class="n">snd_soc_core</span><span class="w"> </span><span class="n">snd_compress</span><span class="w"> </span><span class="n">snd_pcm_dmaengine</span><span class="w"> </span><span class="n">snd_pcm</span><span class="w"> </span><span class="n">snd_seq</span><span class="w"> </span><span class="n">snd_seq_device</span><span class="w"> </span><span class="n">snd_timer</span><span class="w"> </span><span class="n">r8712u</span><span class="p">(</span><span class="n">C</span><span class="p">)</span><span class="w"> </span><span class="n">snd</span><span class="w"> </span><span class="n">spi_bcm2708</span><span class="w"> </span><span class="n">i2c_bcm2708</span><span class="w"></span>
<span class="o">[</span><span class="n"> 4246.239611</span><span class="o">]</span><span class="w"> </span><span class="nl">CPU</span><span class="p">:</span><span class="w"> </span><span class="mi">3</span><span class="w"> </span><span class="nl">PID</span><span class="p">:</span><span class="w"> </span><span class="mi">3468</span><span class="w"> </span><span class="nl">Comm</span><span class="p">:</span><span class="w"> </span><span class="n">insmod</span><span class="w"> </span><span class="nl">Tainted</span><span class="p">:</span><span class="w"> </span><span class="n">G</span><span class="w">         </span><span class="n">C</span><span class="w"> </span><span class="n">O</span><span class="w">   </span><span class="mf">3.18.8</span><span class="o">-</span><span class="n">v7</span><span class="o">+</span><span class="w"> </span><span class="n">#1</span><span class="w"></span>
<span class="o">[</span><span class="n"> 4246.252306</span><span class="o">]</span><span class="w"> </span><span class="nl">task</span><span class="p">:</span><span class="w"> </span><span class="n">b87aa840</span><span class="w"> </span><span class="nl">ti</span><span class="p">:</span><span class="w"> </span><span class="n">b760a000</span><span class="w"> </span><span class="n">task</span><span class="p">.</span><span class="nl">ti</span><span class="p">:</span><span class="w"> </span><span class="n">b760a000</span><span class="w"></span>
<span class="o">[</span><span class="n"> 4246.262985</span><span class="o">]</span><span class="w"> </span><span class="n">PC</span><span class="w"> </span><span class="k">is</span><span class="w"> </span><span class="k">at</span><span class="w"> </span><span class="n">load_module</span><span class="o">+</span><span class="mh">0x1a64</span><span class="o">/</span><span class="mh">0x1f0c</span><span class="w"></span>
<span class="o">[</span><span class="n"> 4246.272699</span><span class="o">]</span><span class="w"> </span><span class="n">LR</span><span class="w"> </span><span class="k">is</span><span class="w"> </span><span class="k">at</span><span class="w"> </span><span class="n">load_module</span><span class="o">+</span><span class="mh">0x1a50</span><span class="o">/</span><span class="mh">0x1f0c</span><span class="w"></span>
<span class="o">[</span><span class="n"> 4246.282373</span><span class="o">]</span><span class="w"> </span><span class="n">pc</span><span class="w"> </span><span class="err">:</span><span class="w"> </span><span class="o">[</span><span class="n">&lt;800940d4&gt;</span><span class="o">]</span><span class="w">    </span><span class="n">lr</span><span class="w"> </span><span class="err">:</span><span class="w"> </span><span class="o">[</span><span class="n">&lt;800940c0&gt;</span><span class="o">]</span><span class="w">    </span><span class="nl">psr</span><span class="p">:</span><span class="w"> </span><span class="mi">90000013</span><span class="w"></span>
<span class="o">[</span><span class="n"> 4246.282373</span><span class="o">]</span><span class="w"> </span><span class="n">sp</span><span class="w"> </span><span class="err">:</span><span class="w"> </span><span class="n">b760be88</span><span class="w">  </span><span class="n">ip</span><span class="w"> </span><span class="err">:</span><span class="w"> </span><span class="mi">7</span><span class="n">f110770</span><span class="w">  </span><span class="n">fp</span><span class="w"> </span><span class="err">:</span><span class="w"> </span><span class="n">b760bf44</span><span class="w"></span>
<span class="o">[</span><span class="n"> 4246.304401</span><span class="o">]</span><span class="w"> </span><span class="nl">r10</span><span class="p">:</span><span class="w"> </span><span class="mi">00000000</span><span class="w">  </span><span class="n">r9</span><span class="w"> </span><span class="err">:</span><span class="w"> </span><span class="mi">7</span><span class="n">f110600</span><span class="w">  </span><span class="n">r8</span><span class="w"> </span><span class="err">:</span><span class="w"> </span><span class="mi">80536</span><span class="n">d44</span><span class="w"></span>
<span class="o">[</span><span class="n"> 4246.314883</span><span class="o">]</span><span class="w"> </span><span class="n">r7</span><span class="w"> </span><span class="err">:</span><span class="w"> </span><span class="n">b86dc8c4</span><span class="w">  </span><span class="n">r6</span><span class="w"> </span><span class="err">:</span><span class="w"> </span><span class="n">fe220b1c</span><span class="w">  </span><span class="n">r5</span><span class="w"> </span><span class="err">:</span><span class="w"> </span><span class="mi">7</span><span class="n">f11060c</span><span class="w">  </span><span class="n">r4</span><span class="w"> </span><span class="err">:</span><span class="w"> </span><span class="n">b760bf48</span><span class="w"></span>
<span class="o">[</span><span class="n"> 4246.326685</span><span class="o">]</span><span class="w"> </span><span class="n">r3</span><span class="w"> </span><span class="err">:</span><span class="w"> </span><span class="mi">00000000</span><span class="w">  </span><span class="n">r2</span><span class="w"> </span><span class="err">:</span><span class="w"> </span><span class="n">b760be70</span><span class="w">  </span><span class="n">r1</span><span class="w"> </span><span class="err">:</span><span class="w"> </span><span class="n">b7555280</span><span class="w">  </span><span class="n">r0</span><span class="w"> </span><span class="err">:</span><span class="w"> </span><span class="mi">807</span><span class="n">f2a3c</span><span class="w"></span>
<span class="o">[</span><span class="n"> 4246.338495</span><span class="o">]</span><span class="w"> </span><span class="nl">Flags</span><span class="p">:</span><span class="w"> </span><span class="n">NzcV</span><span class="w">  </span><span class="n">IRQs</span><span class="w"> </span><span class="k">on</span><span class="w">  </span><span class="n">FIQs</span><span class="w"> </span><span class="k">on</span><span class="w">  </span><span class="n">Mode</span><span class="w"> </span><span class="n">SVC_32</span><span class="w">  </span><span class="n">ISA</span><span class="w"> </span><span class="n">ARM</span><span class="w">  </span><span class="n">Segment</span><span class="w"> </span><span class="k">user</span><span class="w"></span>
<span class="o">[</span><span class="n"> 4246.350916</span><span class="o">]</span><span class="w"> </span><span class="nl">Control</span><span class="p">:</span><span class="w"> </span><span class="mi">10</span><span class="n">c5387d</span><span class="w">  </span><span class="nc">Table</span><span class="err">:</span><span class="w"> </span><span class="mi">35</span><span class="n">dd806a</span><span class="w">  </span><span class="nl">DAC</span><span class="p">:</span><span class="w"> </span><span class="mi">00000015</span><span class="w"></span>
<span class="o">[</span><span class="n"> 4246.361932</span><span class="o">]</span><span class="w"> </span><span class="n">Process</span><span class="w"> </span><span class="n">insmod</span><span class="w"> </span><span class="p">(</span><span class="nl">pid</span><span class="p">:</span><span class="w"> </span><span class="mi">3468</span><span class="p">,</span><span class="w"> </span><span class="n">stack</span><span class="w"> </span><span class="k">limit</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mh">0xb760a238</span><span class="p">)</span><span class="w"></span>
<span class="o">[</span><span class="n"> 4246.373206</span><span class="o">]</span><span class="w"> </span><span class="nl">Stack</span><span class="p">:</span><span class="w"> </span><span class="p">(</span><span class="mh">0xb760be88</span><span class="w"> </span><span class="k">to</span><span class="w"> </span><span class="mh">0xb760c000</span><span class="p">)</span><span class="w"></span>
<span class="o">[</span><span class="n"> 4246.382808</span><span class="o">]</span><span class="w"> </span><span class="nl">be80</span><span class="p">:</span><span class="w">                   </span><span class="mi">7</span><span class="n">f11060c</span><span class="w"> </span><span class="mi">00007</span><span class="n">fff</span><span class="w"> </span><span class="mi">8009168</span><span class="n">c</span><span class="w"> </span><span class="n">ffffffff</span><span class="w"> </span><span class="n">b760bee4</span><span class="w"> </span><span class="n">bd949000</span><span class="w"></span>
<span class="o">[</span><span class="n"> 4246.396352</span><span class="o">]</span><span class="w"> </span><span class="nl">bea0</span><span class="p">:</span><span class="w"> </span><span class="mi">00000000</span><span class="w"> </span><span class="mi">7</span><span class="n">f11060c</span><span class="w"> </span><span class="mi">00000000</span><span class="w"> </span><span class="n">b760bedc</span><span class="w"> </span><span class="mf">807e4</span><span class="n">d78</span><span class="w"> </span><span class="mi">7</span><span class="n">f110648</span><span class="w"> </span><span class="n">b760a000</span><span class="w"> </span><span class="mi">7</span><span class="n">f110770</span><span class="w"></span>
<span class="o">[</span><span class="n"> 4246.409938</span><span class="o">]</span><span class="w"> </span><span class="nl">bec0</span><span class="p">:</span><span class="w"> </span><span class="mi">00001</span><span class="n">f4b</span><span class="w"> </span><span class="mi">806</span><span class="n">c9bdc</span><span class="w"> </span><span class="n">ba7b961c</span><span class="w"> </span><span class="n">b760a000</span><span class="w"> </span><span class="n">b9330000</span><span class="w"> </span><span class="mi">808</span><span class="n">ab8fc</span><span class="w"> </span><span class="mi">76</span><span class="n">fd3000</span><span class="w"> </span><span class="mi">00000000</span><span class="w"></span>
<span class="o">[</span><span class="n"> 4246.423538</span><span class="o">]</span><span class="w"> </span><span class="nl">bee0</span><span class="p">:</span><span class="w"> </span><span class="mi">00000000</span><span class="w"> </span><span class="mi">00000000</span><span class="w"> </span><span class="mi">00000000</span><span class="w"> </span><span class="mi">00000000</span><span class="w"> </span><span class="mi">00000000</span><span class="w"> </span><span class="mi">00000000</span><span class="w"> </span><span class="mi">00000000</span><span class="w"> </span><span class="mi">00000000</span><span class="w"></span>
<span class="o">[</span><span class="n"> 4246.437137</span><span class="o">]</span><span class="w"> </span><span class="nl">bf00</span><span class="p">:</span><span class="w"> </span><span class="mi">00000000</span><span class="w"> </span><span class="mi">00000000</span><span class="w"> </span><span class="mi">00000000</span><span class="w"> </span><span class="mi">00000000</span><span class="w"> </span><span class="mi">00000000</span><span class="w"> </span><span class="mi">00000000</span><span class="w"> </span><span class="mi">00000080</span><span class="w"> </span><span class="mi">00001</span><span class="n">f4b</span><span class="w"></span>
<span class="o">[</span><span class="n"> 4246.450707</span><span class="o">]</span><span class="w"> </span><span class="nl">bf20</span><span class="p">:</span><span class="w"> </span><span class="mi">76</span><span class="n">fd3000</span><span class="w"> </span><span class="mi">76</span><span class="n">f91948</span><span class="w"> </span><span class="mi">00000080</span><span class="w"> </span><span class="mi">8000</span><span class="n">f0a4</span><span class="w"> </span><span class="n">b760a000</span><span class="w"> </span><span class="mi">00000000</span><span class="w"> </span><span class="n">b760bfa4</span><span class="w"> </span><span class="n">b760bf48</span><span class="w"></span>
<span class="o">[</span><span class="n"> 4246.464292</span><span class="o">]</span><span class="w"> </span><span class="nl">bf40</span><span class="p">:</span><span class="w"> </span><span class="mi">80094664</span><span class="w"> </span><span class="mi">8009267</span><span class="n">c</span><span class="w"> </span><span class="n">bd949000</span><span class="w"> </span><span class="mi">00001</span><span class="n">f4b</span><span class="w"> </span><span class="n">bd949f3c</span><span class="w"> </span><span class="n">bd949de3</span><span class="w"> </span><span class="n">bd94acc4</span><span class="w"> </span><span class="mi">00000850</span><span class="w"></span>
<span class="o">[</span><span class="n"> 4246.477932</span><span class="o">]</span><span class="w"> </span><span class="nl">bf60</span><span class="p">:</span><span class="w"> </span><span class="mi">00000940</span><span class="w"> </span><span class="mi">00000000</span><span class="w"> </span><span class="mi">00000000</span><span class="w"> </span><span class="mi">00000000</span><span class="w"> </span><span class="mi">0000001</span><span class="n">f</span><span class="w"> </span><span class="mi">00000020</span><span class="w"> </span><span class="mi">00000017</span><span class="w"> </span><span class="mi">00000014</span><span class="w"></span>
<span class="o">[</span><span class="n"> 4246.491605</span><span class="o">]</span><span class="w"> </span><span class="nl">bf80</span><span class="p">:</span><span class="w"> </span><span class="mi">00000010</span><span class="w"> </span><span class="mi">00000000</span><span class="w"> </span><span class="mi">00000000</span><span class="w"> </span><span class="mi">7</span><span class="n">eb7861c</span><span class="w"> </span><span class="mi">00000000</span><span class="w"> </span><span class="mi">7768</span><span class="n">b038</span><span class="w"> </span><span class="mi">00000000</span><span class="w"> </span><span class="n">b760bfa8</span><span class="w"></span>
<span class="o">[</span><span class="n"> 4246.505297</span><span class="o">]</span><span class="w"> </span><span class="nl">bfa0</span><span class="p">:</span><span class="w"> </span><span class="mi">8000</span><span class="n">ee20</span><span class="w"> </span><span class="mi">80094588</span><span class="w"> </span><span class="mi">7</span><span class="n">eb7861c</span><span class="w"> </span><span class="mi">00000000</span><span class="w"> </span><span class="mi">76</span><span class="n">fd3000</span><span class="w"> </span><span class="mi">00001</span><span class="n">f4b</span><span class="w"> </span><span class="mi">76</span><span class="n">f91948</span><span class="w"> </span><span class="mi">76</span><span class="n">fd3000</span><span class="w"></span>
<span class="o">[</span><span class="n"> 4246.519052</span><span class="o">]</span><span class="w"> </span><span class="nl">bfc0</span><span class="p">:</span><span class="w"> </span><span class="mi">7</span><span class="n">eb7861c</span><span class="w"> </span><span class="mi">00000000</span><span class="w"> </span><span class="mi">7768</span><span class="n">b038</span><span class="w"> </span><span class="mi">00000080</span><span class="w"> </span><span class="mi">7768</span><span class="n">af80</span><span class="w"> </span><span class="mi">00001</span><span class="n">f4b</span><span class="w"> </span><span class="mi">76</span><span class="n">f91948</span><span class="w"> </span><span class="mi">00000000</span><span class="w"></span>
<span class="o">[</span><span class="n"> 4246.532810</span><span class="o">]</span><span class="w"> </span><span class="nl">bfe0</span><span class="p">:</span><span class="w"> </span><span class="mi">00000000</span><span class="w"> </span><span class="mi">7</span><span class="n">eb785c4</span><span class="w"> </span><span class="mi">76</span><span class="n">f88fb4</span><span class="w"> </span><span class="mi">76</span><span class="n">ef3ab4</span><span class="w"> </span><span class="mi">60000010</span><span class="w"> </span><span class="mi">76</span><span class="n">fd3000</span><span class="w"> </span><span class="n">d466662e</span><span class="w"> </span><span class="n">d5f7abd0</span><span class="w"></span>
<span class="o">[</span><span class="n"> 4246.546635</span><span class="o">]</span><span class="w"> </span><span class="o">[</span><span class="n">&lt;800940d4&gt;</span><span class="o">]</span><span class="w"> </span><span class="p">(</span><span class="n">load_module</span><span class="p">)</span><span class="w"> </span><span class="k">from</span><span class="w"> </span><span class="o">[</span><span class="n">&lt;80094664&gt;</span><span class="o">]</span><span class="w"> </span><span class="p">(</span><span class="n">SyS_init_module</span><span class="o">+</span><span class="mh">0xe8</span><span class="o">/</span><span class="mh">0xfc</span><span class="p">)</span><span class="w"></span>
<span class="o">[</span><span class="n"> 4246.560087</span><span class="o">]</span><span class="w"> </span><span class="o">[</span><span class="n">&lt;80094664&gt;</span><span class="o">]</span><span class="w"> </span><span class="p">(</span><span class="n">SyS_init_module</span><span class="p">)</span><span class="w"> </span><span class="k">from</span><span class="w"> </span><span class="o">[</span><span class="n">&lt;8000ee20&gt;</span><span class="o">]</span><span class="w"> </span><span class="p">(</span><span class="n">ret_fast_syscall</span><span class="o">+</span><span class="mh">0x0</span><span class="o">/</span><span class="mh">0x48</span><span class="p">)</span><span class="w"></span>
<span class="o">[</span><span class="n"> 4246.573935</span><span class="o">]</span><span class="w"> </span><span class="nl">Code</span><span class="p">:</span><span class="w"> </span><span class="n">e51bc088</span><span class="w"> </span><span class="n">e15c0006</span><span class="w"> </span><span class="n">e2466008</span><span class="w"> </span><span class="mi">0</span><span class="n">a000009</span><span class="w"> </span><span class="p">(</span><span class="n">e5963014</span><span class="p">)</span><span class="w"> </span>
<span class="o">[</span><span class="n"> 4246.604593</span><span class="o">]</span><span class="w"> </span><span class="c1">---[ end trace 8e4bd0982f9f1fd0 ]---</span>
</code></pre></div>


<p>It basically says that there was an error trying to access the wrong part of the
memory from the <em>insmod</em> process.</p>
<p>At this point I decided to stop experimenting with this approach. I was getting
frustrated with constant fighting with all kind of errors. When I initially started
writing this blog post I wanted to describe the method to cross-compile Linux
kernel image and <em>kbuild</em> build system. Unfortunately, although it may sound
appealing to speed up the process by cross compiling on x86 machine, the 
complication with various stuff make it more time consuming that compiling directly
on Raspberry Pi. I know myself good enough that I know I wont quit this easy.
I will probably return to this problem on some other occasion and tried again,
be assured that I will write a blog post If I succeed.</p>
<h2>The easy way</h2>
<p>At the end I dropped the cross-compilation idea and resorted to compiling kernel
on the RPi itself. This can also serve as a performance test of the new RPi. 
I overclocked it to 1000MHz (using raspi-config I selected the RPi2 setting).</p>
<p>The compilation of kernel took something less than 2 hours, quite decent result
compared to 17 minutes it takes on my laptop with not-so-new i3 and 6GB of RAM.</p>
<p>The following figure shows the temperature during the compilation. The temperature
was captured every minute with a Cron job which read from 
<strong>/sys/class/thermal/thermal_zone0/temp</strong></p>
<p style="width:90%; display: block; margin-left: auto; margin-right: auto;"><img alt="RPi temperature" src="./images/pi_temp_during_compile.png"></p>
<p>Finally, using freshly compiled kernel on RPi, I managed to get compile my 
module and to load it in kernel (debug message from kernel):</p>
<div class="highlight"><pre><span></span><code><span class="go">[   38.324756] ============================================</span>
<span class="go">[   38.324786]        Pi64 driver by Jan Marjanovic        </span>
<span class="go">[   38.324796] </span>
<span class="go">[   38.324808]   built: Mar  1 2015 11:38:10</span>
<span class="go">[   38.324818] ============================================</span>
</code></pre></div>
        </div><!-- /.entry-content -->
<a href="https://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-via="janmarjanovic">Tweet</a><script type="text/javascript" src="https://platform.twitter.com/widgets.js"></script><br/><br/>

      </article>
    </div>
</section>
        <section id="extras" >
        
        </section><!-- /#extras -->
	
        <footer id="contentinfo" >
                <address id="about" class="vcard ">
                Proudly powered by <a href="https://getpelican.com/" target="_blank">Pelican</a>, which takes
                great advantage of <a href="https://python.org" target="_blank">Python</a>.
		
                </address><!-- /#about -->
		

                
        </footer><!-- /#contentinfo -->

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-56555055-1', 'auto');
  ga('send', 'pageview');

</script></body>
</html>